package com.huiztech.watersoil.view;

import java.util.ArrayList;

import com.huiztech.watersoil.R;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
/**
 * 弹出窗口视图
 * @author alin
 *
 */
public class PopMenu {
	private ArrayList<String> itemList;
	private Context context;
	private PopupWindow popupWindow;
	private Button changed_button;
	private TextView help_tag;
	private String help_tag_text="";
	private int width = 400;
	
	public PopMenu(Context context,int width) {
		this.width = width;
		// TODO Auto-generated constructor stub
		this.context = context;
		View view = LayoutInflater.from(context)
				.inflate(R.layout.popmenu, null);
		help_tag = (TextView) view.findViewById(R.id.help_tag);
		help_tag.setText(R.string.intro0);

		popupWindow = new PopupWindow(view, width,
				LayoutParams.WRAP_CONTENT);

		// 这个是为了点击“返回Back”也能使其消失，并且并不会影响你的背景
		popupWindow.setBackgroundDrawable(new BitmapDrawable());
	}
	
	public void setOnClickListener(OnClickListener listener){
		changed_button.setOnClickListener(listener);
	}
	
	public void setText(int intro_id){
		if(intro_id==1){
			help_tag.setText(R.string.intro1);
		}
		if(intro_id==2){
			help_tag.setText(R.string.intro2);
		}
		if(intro_id==3){
			help_tag.setText(R.string.intro3);
		}
		if(intro_id==4){
			help_tag.setText(R.string.intro4);
		}
		if(intro_id==5){
			help_tag.setText(R.string.intro5);
		}
		if(intro_id==6){
			help_tag.setText(R.string.intro6);
		}
		if(intro_id==7){
			help_tag.setText(R.string.intro7);
		}
		if(intro_id==8){
			help_tag.setText(R.string.intro8);
		}
		if(intro_id==9){
			help_tag.setText(R.string.intro9);
		}
		if(intro_id==10){
			help_tag.setText(R.string.intro10);
		}
		if(intro_id==11){
			help_tag.setText(R.string.intro11);
		}
		if(intro_id==0){
			help_tag.setText(R.string.intro0);
		}
	}

	// 下拉式 弹出 pop菜单 parent 右下角
	public void showAsDropDown(View parent) {
		popupWindow.showAsDropDown(parent,
				10,
				// 保证尺寸是根据屏幕像素密度来的
				context.getResources().getDimensionPixelSize(
						R.dimen.popmenu_yoff));

		// 使其聚集
		popupWindow.setFocusable(true);
		// 设置允许在外点击消失
		popupWindow.setOutsideTouchable(true);
		// 刷新状态
		popupWindow.update();
	}

	// 隐藏菜单
	public void dismiss() {
		popupWindow.dismiss();
	}

}
